<?php TPL::output('global/header.tpl.htm'); ?>

<?php if(get_setting('advanced_editor_enable')=="Y"){ ?>
<script type="text/javascript" src="<?php echo G_STATIC_URL; ?>/js/ueditor/ueditor.config.js?v=<?php echo G_VERSION_BUILD; ?>"></script>
<script type="text/javascript" src="<?php echo G_STATIC_URL; ?>/js/ueditor/ueditor.all.js?v=<?php echo G_VERSION_BUILD; ?>"></script>
<script type="text/javascript" src="<?php echo G_STATIC_URL; ?>/js/ueditor/lang/zh-cn/zh-cn.js?v=<?php echo G_VERSION_BUILD; ?>"></script>
<?php }?>

<div class="aw-container-wrap">
	<div class="container aw-publish aw-publish-article">
		<div class="row">
			<div class="aw-content-wrap clearfix">
				<div class="col-sm-12 col-md-9 aw-main-content">
					<!-- tab 切换 -->
					<ul class="nav nav-tabs aw-nav-tabs active">
						<li class="active"><a href="publish/article/"><?php _e('文章'); ?></a></li>
						<?php if ($this->user_info['permission']['publish_question']) { ?>
						<li><a href="publish/"><?php _e('问题'); ?></a></li>
						<?php } ?>
						<h2 class="hidden-xs"><i class="icon icon-ask"></i> <?php _e('发起'); ?></h2>
					</ul>
					<!-- end tab 切换 -->
					<form action="publish/ajax/<?php if ($this->article_info['id']) { ?>modify<?php } else { ?>publish<?php } ?>_article/" method="post" id="question_form" onsubmit="return false;">
						<input type="hidden" name="post_hash" value="<?php echo new_post_hash(); ?>" />
						<input type="hidden" name="attach_access_key" value="<?php echo $this->attach_access_key; ?>" />
						<input type="hidden" name="article_id" id="article_id" value="<?php echo $this->article_info['id']; ?>" />
						<input type="hidden" name="logo_img"
                                   value="<?php echo $this->article_info['article_img']?$this->article_info['article_img']:G_STATIC_URL.'/css/default/img/default-cover.jpg'; ?>"/>
						<?php if ($this->article_category_list) { ?>
							<select name="category_id" class="collapse" id="category_id">
								<option value="0">- <?php _e('请选择分类'); ?> -</option>
								<?php echo $this->article_category_list; ?>
							</select>
							<?php } ?>
						<div class="aw-mod aw-mod-publish">
							<div class="mod-body">
								<h3><?php _e('文章标题'); ?>:</h3>
								<!-- 文章标题 -->
								<div class="aw-publish-title<?php if (!$this->article_category_list) { ?> active<?php } ?>">
									<input type="text" name="title" value="<?php echo $this->article_info['title']; ?>" class="form-control" />
									<?php if ($this->article_category_list) { ?>
									<div class="aw-dropdown aw-question-dropdown">
										<i class="aw-icon i-dropdown-triangle active"></i>
										<p class="title"><?php _e('没有找到相关结果'); ?></p>
										<ul class="aw-question-dropdown-list"></ul>
									</div>
									<div class="dropdown">
										<div class="dropdown-toggle" data-toggle="dropdown">
											<span id="aw-topic-tags-select"><?php _e('选择分类'); ?></span>
											<a href="javascript:;"><i class="icon icon-down"></i></a></a>
										</div>
									</div>
									<?php } ?>
								</div>
								<!-- end 文章标题 -->

								<!-- 文章封面图 -->
								<?php if($this->user_info['permission']['upload_attach']){ ?>
								<h3><?php _e('文章封面'); ?>:</h3>
                                <div class="side-bar">
                                    <dl>
                                        <dt class="pull-left">
                                            <img class="aw-border-radius-5"
                                                 src="<?php if ($this->article_info['article_img']) {
                                                     echo $this->article_info['article_img'];
                                                 } else {
                                                     echo G_STATIC_URL . '/css/default/img/default-cover.jpg';
                                                 } ?>"
                                                 id="logo_img" style="height: 100px;width: 100px;"></dt>
                                        <dd class="pull-left">
                                            <h5><?php _e('封面设置');?></h5>
                                            <p><?php _e('支持 jpg、gif、png 等格式的图片 建议图片尺寸为240*150');?></p>
                                            <a class="btn btn-mini btn-success" id="logo_uploader"
                                               href="javascript:;"><?php _e('上传封面');?></a>
                                            <span id="logo_uploading_status" class="collapse"><i
                                                        class="aw-loading"></i> <?php _e('文件上传中...'); ?></span>
                                        </dd>
                                    </dl>
                                </div>
                                <div class="clearfix"></div>
                                <?php } ?>
								<!-- end 文章封面图 -->

								<h3><?php _e('文章内容'); ?>:</h3>
								<div class="aw-mod aw-editor-box">
									<div class="mod-head">
										<div class="wmd-panel">
											<script class="fuwenben" style="display: block" id="container" type="text/plain" name="message"><?php echo html_entity_decode($this->article_info['message']); ?></script></p>
										</div>
									</div>

									<span style="color: #999999;font-size: 10px;" >如需问题补充中@其他用户,需要在名字后面添加空格。例如：我有一个问题想要@陈老师 来解答。</span>

									<span style="color: #999999;font-size: 10px;" id="answer_content_message">&nbsp;</span>
								</div>


								<h3><?php _e('添加话题'); ?>:</h3>
								<div class="aw-topic-bar" data-type="publish">
									<div class="tag-bar clearfix">
										<?php if ($_GET['topic_title']) { ?>
											<span class="topic-tag">
												<a class="text"><?php echo urldecode($_GET['topic_title']); ?></a>
												<a class="close" onclick="$(this).parents('.topic-tag').remove();">
													<i class="icon icon-delete"></i>
												</a>
												<button class="close aw-close" onclick="">×</button></span><input type="hidden" value="<?php echo urldecode($_GET['topic_title']); ?>" name="topics[]" />
											</span>
										<?php } ?>

										<?php if ($_POST['topics']) { ?>
											<?php foreach ($_POST['topics'] AS $key => $val) { ?>
												<span class="topic-tag">
													<a class="text"><?php echo $val; ?></a>
													<input type="hidden" value="<?php echo $val; ?>" name="topics[]" />
												</span>
											<?php } ?>
										<?php } else if ($this->article_topics) { ?>
											<?php foreach ($this->article_topics AS $key => $val) { ?>
												<span class="topic-tag">
													<a class="text"><?php echo $val['topic_title']; ?></a>
													<input type="hidden" value="<?php echo $val['topic_title']; ?>" name="topics[]" />
												</span>
											<?php } ?>
										<?php } ?>

										<span class="aw-edit-topic icon-inverse"><i class="icon icon-edit"></i> <?php _e('编辑话题'); ?></span>
									</div>
								</div>

								<?php if ($this->recent_topics) { ?>
								<h3><?php _e('最近话题'); ?>:</h3>
								<div class="aw-topic-bar">
									<div class="topic-bar clearfix">
										<?php foreach($this->recent_topics as $key => $val) { ?>
										<span class="topic-tag" onclick="$('#aw_edit_topic_title').val('<?php echo $val; ?>');$('.add').click();$(this).hide();">
											<a class="text">
												<?php echo $val; ?>
											</a>
										</span>
										<?php } ?>
									</div>
								</div>
								<?php } ?>

								<?php if ($this->human_valid) { ?>
								<div class="aw-auth-img clearfix">
									<em class="auth-img pull-right"><img src="" onclick="this.src = G_BASE_URL + '/account/captcha/' + Math.floor(Math.random() * 10000);" id="captcha"  /></em>
									<input class="pull-right form-control" type="text" name="seccode_verify" placeholder="验证码" />
								</div>
								<?php } ?>
							</div>
							<div class="mod-footer clearfix">
								<?php if (get_setting('integral_system_enabled') == 'Y') { ?><a href="integral/rule/" target="_blank">[<?php _e('积分规则'); ?>]</a><?php } ?>
								<span class="aw-anonymity">
									<?php if ($this->article_info['id'] AND ($this->user_info['permission']['is_administortar'] OR $this->user_info['permission']['is_moderator'])) { ?>
									<label><input type="checkbox" class="pull-left" value="1" name="do_delete" />
										<?php _e('删除文章'); ?></label>
									<?php } ?>
								</span>
								<a class="btn btn-large btn-success btn-publish-submit" id="publish_submit" onclick="AWS.ajax_post($('#question_form')); return false;"><?php _e('确认发起'); ?></a>
							</div>
						</div>
					</form>
				</div>
				<!-- 侧边栏 -->
				<div class="col-sm-12 col-md-3 aw-side-bar hidden-xs">
					<!-- 文章发起指南 -->
					<div class="aw-mod publish-help">
						<div class="mod-head">
							<h3><?php _e('文章发起指南'); ?></h3>
						</div>
						<div class="mod-body">
							<p><b>• <?php _e('文章标题'); ?>:</b> <?php _e('请用准确的语言描述您发布的文章思想'); ?></p>
							<p><b>• <?php _e('文章补充'); ?>:</b> <?php _e('详细补充您的文章内容, 并提供一些相关的素材以供参与者更多的了解您所要文章的主题思想'); ?></p>
							<p><b>• <?php _e('选择话题'); ?>:</b> <?php _e('选择一个或者多个合适的话题, 让您发布的文章得到更多有相同兴趣的人参与. 所有人可以在您发布文章之后添加和编辑该文章所属的话题'); ?></p>
						</div>
					</div>
					<!-- end 文章发起指南 -->
				</div>
				<!-- end 侧边栏 -->
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
	var ATTACH_ACCESS_KEY = '<?php echo $this->attach_access_key; ?>';
	var CATEGORY_ID = <?php echo $this->article_info['category_id']; ?>;
	var PUBLISH_TYPE = 'article';
    var EDITOR_CALLBACK;
	var EDITOR;
	var ANSWER_TYPE = 'article';
	var logoUpload = new FileUpload('avatar', $('#logo_uploader'), $('#logo_img'), G_BASE_URL + '/publish/ajax/logo_upload/', {
            loading_status: '#logo_uploading_status',
            tag: 'logo',
            accept:'image/*'
        }, function () {
            $('input[name="logo_img"]').val($('#logo_img').attr('src'));
        });
	$(function(){
		if ($('#container').length)
	    {
	    	if (G_ADVANCED_EDITOR_ENABLE == 'Y')
	    	{   


	    		var EDITOR = UE.getEditor('container');

	    		EDITOR_CALLBACK = function (evt)
	    		{   

	    			if(EDITOR.getContent().length)
	                {       

	    			  		$.post(G_BASE_URL + '/account/ajax/save_add_draft/', {'type':ANSWER_TYPE,'message':EDITOR.getContent()}, function (result) {
	                            $('#answer_content_message').html(result.err + ' <a href="#" onclick="$(\'#container\').attr(\'value\', \'\'); AWS.User.delete_add_draft(ANSWER_TYPE); $(this).parent().html(\' \'); return false;">' + _t('删除草稿') + '</a>');
	                        }, 'json');
	                }
	    		}


	    		EDITOR.on( 'blur', EDITOR_CALLBACK);
	    	}
	    }
	});
</script>

<script>
var topic_flag= "<?php echo $this->user_info['permission']['create_topic']?>";
var $editor;
var markdownIsSave = false;
var markdownContent;
function fuwenben(){
    $('.fuwenben').show();
    $('.marktext').hide();
    $("#text_fuwenben_radio").attr('checked',true);
    $("#text_markdown_radio").attr('checked',false);
}
function textmarkdown(){
    $('.fuwenben').hide();
    $('.marktext').show();
    $("#text_fuwenben_radio").attr('checked',false);
    $("#text_markdown_radio").attr('checked',true);
}

function submitContent(){
    if($('#text_fuwenben_radio').attr('checked')=='checked'){
        $('#markdownFrameHide').attr('name','mess');
        $('.fuwenben').attr('name','message');
        AWS.ajax_post($('#question_form'));
    }else{
        $('.fuwenben').attr('name','mess');
        $('#markdownFrameHide').attr('name','message');
        if(markdownIsSave == true) {
            $('#markdownFrameHide').html(markdownContent);
            AWS.ajax_post($('#question_form'));
        }else{
            AWS.alert('请点击保存');
        }
    }
}
function keypress()  {
    if(topic_flag){
        if (event.keyCode == 13 ) {
            $('.add').click();
            $(this).parents('.aw-edit-topic-box').find('.aw-dropdown').hide();
        }
    }
}
</script>

<?php TPL::output('global/footer.tpl.htm'); ?>